﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace B.S.GridManage.Api.Write.Filters
{
    /// <summary>
    /// 全局异常过滤器
    /// </summary>
    public class MyExceptionFilter : IExceptionFilter
    {
        private readonly ILogger<MyExceptionFilter> logger;

        public MyExceptionFilter(ILogger<MyExceptionFilter> logger)
        {
            this.logger = logger;
        }
        public void OnException(ExceptionContext context)
        {
            logger.LogError($"发生全局异常:{context.Exception.Message}");
            context.ExceptionHandled = true;
             
        }
    }
}
